package cn.wolfcode.luowowo.article.query;

import cn.wolfcode.luowowo.common.query.QueryObject;
import cn.wolfcode.luowowo.common.util.DateUtil;
import lombok.Getter;
import lombok.Setter;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 名字
 * @company 公司
 * @create 2019-09-26 14:12
 */
@Getter
@Setter
public class AnswerQuery extends QueryObject {
    //日期
    public static final int RANGE_DAY = 1; //当天
    public static final int RANGE_WEEK = 2; //本周
    public static final int RANGE_MONTH = 3; //本月

    //产询条件
    public static final int CONDITION_GOLD = 1; //按金牌数
    public static final int CONDITION_ANSWER = 2; //按回答数
    public static final int CONDITION_THUMB = 3; //按顶的次数

    //这里也就是一个sum的条件, 除了金牌有一个条件 其他都没有 就判断是否等于level 等于就加上
    public String getConditionType() {
        switch (condition) {
            case CONDITION_GOLD:
                return "count(id)";  // 金牌数
            case CONDITION_ANSWER:
                return "count(id)"; //回答数
            default:
                return "sum(thumsupnum)"; //被顶的次数
        }
    }

    //范围
    private int range = RANGE_DAY;

    //条件
    private int condition = CONDITION_GOLD;

    //开始日期
    public String  getEndDate() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:ss");
        Date date = new Date();
        switch (range) {
            case RANGE_DAY:
                return simpleDateFormat.format(DateUtil.getEndDate(date));
            case RANGE_WEEK:
                return simpleDateFormat.format(DateUtil.getLastDayOfWeek(date));
            default:
                return simpleDateFormat.format(DateUtil.getCurrentMonthLastDay(date));
        }
    }

    //结束日期
    public String getBeginDate() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:ss");
        Date date = new Date();
        switch (range) {
            case RANGE_DAY:
                return simpleDateFormat.format(DateUtil.getBeginDate(date));
            case RANGE_WEEK:
                return simpleDateFormat.format(DateUtil.getFirstDayOfWeek(date));
            default:
                return simpleDateFormat.format(DateUtil.getCurrentMonthFirstDay(date));
        }
    }


}
